﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;

using System.Text;
using Module.Common.Models;
using Module.Core.EntitiesInfo.TablesInfo;

namespace Module.Core.DAO.DAO
{
    public class OnlineSupportsDAO
    {
        #region Fields

        protected string connectionStringName;

        #endregion

        #region Methods

        /// <summary>
        /// Saves a record to the Singer table.
        /// </summary>
        public virtual int Insert(OnlineSupportsInfo onlineSupportsInfo)
        {
            SqlParameter[] parameters = new SqlParameter[]
			{
				new SqlParameter("@Title", onlineSupportsInfo.Title),
				new SqlParameter("@Description", onlineSupportsInfo.Description),
				new SqlParameter("@Yahoo", onlineSupportsInfo.Yahoo),
				new SqlParameter("@Sky", onlineSupportsInfo.Sky),
				new SqlParameter("@Email", onlineSupportsInfo.Email),
				new SqlParameter("@SupportType", onlineSupportsInfo.SupportType),
				new SqlParameter("@NickName", onlineSupportsInfo.Nickname),
				new SqlParameter("@Phone", onlineSupportsInfo.Phone),
				new SqlParameter("@Mobile", onlineSupportsInfo.Mobile),
				new SqlParameter("@Priority", onlineSupportsInfo.Priority)
                //new SqlParameter("@Status", onlineSupportsInfo.Status)
			};

            return (int)SqlClientUtility.ExecuteScalar(connectionStringName, CommandType.StoredProcedure, "OnlineSupports_Insert", parameters);
        }

        /// <summary>
        /// Updates a record in the Singer table.
        /// </summary>
        public virtual void Update(OnlineSupportsInfo onlineSupportsInfo)
        {
            SqlParameter[] parameters = new SqlParameter[]
			{
				new SqlParameter("@OnlineSupportId", onlineSupportsInfo.OnlineSupportId),
				new SqlParameter("@Title", onlineSupportsInfo.Title),
				new SqlParameter("@Description", onlineSupportsInfo.Description),
				new SqlParameter("@Yahoo", onlineSupportsInfo.Yahoo),
				new SqlParameter("@Sky", onlineSupportsInfo.Sky),
				new SqlParameter("@Email", onlineSupportsInfo.Email),
				new SqlParameter("@SupportType", onlineSupportsInfo.SupportType),
				new SqlParameter("@NickName", onlineSupportsInfo.Nickname),
				new SqlParameter("@Phone", onlineSupportsInfo.Phone),
				new SqlParameter("@Mobile", onlineSupportsInfo.Mobile),
				new SqlParameter("@Priority", onlineSupportsInfo.Priority)
                //new SqlParameter("@Status", onlineSupportsInfo.Status)
				
			};

            SqlClientUtility.ExecuteNonQuery(connectionStringName, CommandType.StoredProcedure, "OnlineSupports_Update", parameters);
        }

        /// <summary>
        /// Deletes a record from the Singer table by its primary key.
        /// </summary>
        public virtual void Delete(int onlineSupportId)
        {
            SqlParameter[] parameters = new SqlParameter[]
			{
				new SqlParameter("@OnlineSupportId", onlineSupportId)
			};

            SqlClientUtility.ExecuteNonQuery(connectionStringName, CommandType.StoredProcedure, "OnlineSupports_Delete", parameters);
        }

        /// <summary>
        /// Selects a single record from the Singer table.
        /// </summary>
        public virtual OnlineSupportsInfo Select(int onlineSupportId)
        {
            SqlParameter[] parameters = new SqlParameter[]
			{
				new SqlParameter("@OnlineSuport_Id", onlineSupportId)
			};

            using (SqlDataReader dataReader = SqlClientUtility.ExecuteReader(connectionStringName, CommandType.StoredProcedure, "OnlineSupports_Select", parameters))
            {
                if (dataReader.Read())
                {
                    return MakeOblineSupportsInfo(dataReader);
                }
                else
                {
                    return null;
                }
            }
        }

        /// <summary>
        /// Selects all records from the Singer table.
        /// </summary>
        public CHRTList<OnlineSupportsInfo> SelectAll(int status)
        {
            SqlParameter[] parameters = new SqlParameter[]
                                          {
                                              new SqlParameter("@Status",status)
		};
            using (SqlDataReader dataReader = SqlClientUtility.ExecuteReader(connectionStringName, CommandType.StoredProcedure, "OnlineSupports_SelectAll", parameters))
            {
                CHRTList<OnlineSupportsInfo> onlineSupportsInfos = new CHRTList<OnlineSupportsInfo>();
                while (dataReader.Read())
                {
                    OnlineSupportsInfo onlineSupportsInfo = MakeOblineSupportsInfo(dataReader);
                    onlineSupportsInfos.Add(onlineSupportsInfo);
                }

                return onlineSupportsInfos;
            }
        }
        public CHRTList<OnlineSupportsInfo> SearchAll(string NickName, int status, int from, int to)
        {
            SqlParameter[] parameters = new SqlParameter[]
                                          {
                                              new SqlParameter("@NickName",NickName),
                                              new SqlParameter("@Status",status),
                                              new SqlParameter("@From",from),
                                              new SqlParameter("@To",to)
		};
            using (SqlDataReader dataReader = SqlClientUtility.ExecuteReader(connectionStringName, CommandType.StoredProcedure, "OnlineSupports_SearchAll", parameters))
            {
                CHRTList<OnlineSupportsInfo> onlineSupportsInfos = new CHRTList<OnlineSupportsInfo>();
                while (dataReader.Read())
                {
                    OnlineSupportsInfo onlineSupportsInfo = MakeOblineSupportsInfo(dataReader);
                    onlineSupportsInfos.Add(onlineSupportsInfo);
                }

                return onlineSupportsInfos;
            }
        }
        public int GetCount(string NickName, int status)
        {
            SqlParameter[] parameters = new SqlParameter[]
                                            {
                                                new SqlParameter("@NickName", NickName),
                                                new SqlParameter("@Status", status)
                                            };
            return
                (int)SqlClientUtility.ExecuteScalar(connectionStringName, CommandType.StoredProcedure, "OnlineSupports_GetCount", parameters);

        }
        /// <summary>
        /// Creates a new instance of the Singer class and populates it with data from the specified SqlDataReader.
        /// </summary>
        protected virtual OnlineSupportsInfo MakeOblineSupportsInfo(SqlDataReader dataReader)
        {
            OnlineSupportsInfo onlineSupportsInfo = new OnlineSupportsInfo();
            onlineSupportsInfo.OnlineSupportId = SqlClientUtility.GetInt32(dataReader, DbConstants.ONLINESUPPORTS.ONLINESUPPORTID, 0);
            onlineSupportsInfo.Title = SqlClientUtility.GetString(dataReader, DbConstants.ONLINESUPPORTS.TITLE, String.Empty);
            onlineSupportsInfo.Description = SqlClientUtility.GetString(dataReader, DbConstants.ONLINESUPPORTS.DESCRIPTION, String.Empty);
            onlineSupportsInfo.Yahoo = SqlClientUtility.GetString(dataReader, DbConstants.ONLINESUPPORTS.YAHOO, String.Empty);
            onlineSupportsInfo.Sky = SqlClientUtility.GetString(dataReader, DbConstants.ONLINESUPPORTS.SKY, String.Empty);
            onlineSupportsInfo.SupportType = SqlClientUtility.GetInt32(dataReader, DbConstants.ONLINESUPPORTS.SUPPORTTYPE, 0);
            onlineSupportsInfo.Nickname = SqlClientUtility.GetString(dataReader, DbConstants.ONLINESUPPORTS.NICKNAME, String.Empty);
            onlineSupportsInfo.Email = SqlClientUtility.GetString(dataReader, DbConstants.ONLINESUPPORTS.EMAIL, String.Empty);
            onlineSupportsInfo.Phone = SqlClientUtility.GetString(dataReader, DbConstants.ONLINESUPPORTS.PHONE, String.Empty);
            onlineSupportsInfo.Mobile = SqlClientUtility.GetString(dataReader, DbConstants.ONLINESUPPORTS.MOBILE, String.Empty);
            onlineSupportsInfo.Priority = SqlClientUtility.GetInt32(dataReader, DbConstants.ONLINESUPPORTS.PRIORITY, 0);
            onlineSupportsInfo.Status = SqlClientUtility.GetInt32(dataReader, DbConstants.ONLINESUPPORTS.STATUS, 0);

            return onlineSupportsInfo;
        }

        #endregion
    }
}
